﻿using System.Collections.Generic;
using System.Data.SqlClient;

namespace BLL.Services.AutoCompleteService
{
    public class AutoCompleteService : IAutoCompleteService
    {
        private readonly AutoCompleteCollection _autoCompleteCollection;

        public AutoCompleteService(AutoCompleteCollection autoCompleteCollection)
        {
            _autoCompleteCollection = autoCompleteCollection;
        }

        public IEnumerable<AutoCompleteItem> GetAuthors(string searchPattern)
        {
            try
            {
                return _autoCompleteCollection.GetAuthors(searchPattern);
            }
            catch (SqlException ex)
            {
               throw new ServiceException(ex.Message);
            }
        }

        public IEnumerable<AutoCompleteItem> GetCategories(string searchPattern)
        {
            try
            {
                return _autoCompleteCollection.GetCategories(searchPattern);
            }
            catch (SqlException ex)
            {
                throw new ServiceException(ex.Message);
            }
        }

        public IEnumerable<AutoCompleteItem> GetUsers(string searchPattern)
        {
            try
            {
                return _autoCompleteCollection.GetUsersEmails(searchPattern);
            }
            catch (SqlException ex)
            {
                throw new ServiceException(ex.Message);
            }
        }

        public IEnumerable<AutoCompleteItem> GetBooks(string searchPattern)
        {
            try
            {
                return _autoCompleteCollection.GetBooks(searchPattern);
            }
            catch (SqlException ex)
            {
                throw new ServiceException(ex.Message);
            }
        }
    }
}
